package bit.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bit.dao.MemberDAO;
import bit.dao.MemberDTO;

public class MemberInsertAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		
		//form 파라메터를 받는작업(model=>DTO)
		String name = req.getParameter("name");
		String age = req.getParameter("age");
		String addr = req.getParameter("addr");
		String tel = req.getParameter("tel");
		
		System.out.println(name+","+age+","+addr+","+tel);
		
		MemberDTO dto = new MemberDTO();
		dto.setName(name);
		dto.setAge(Integer.parseInt(age));
		dto.setAddr(addr);
		dto.setTel(tel);
		
		MemberDAO dao = new MemberDAO();
		int cnt = dao.memInsert(dto);
		ActionForward forward = null;
		
		if(cnt>0){
			forward = new ActionForward();
			forward.setPath("list.do");
			forward.setRedirect(true);
		}
		
		return forward;
	}

}
